feat: Preserve pointer types in generic iterators#409
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request enhances the generic type normalization logic to properly preserve pointer types in generic iterators, specifically addressing the need to handle types like iter.Seq2[*github.Artifact, error] where pointer prefixes must be maintained.
Changes:
- Refactored
normalizedGenericTypeNameto handle multiple type parameters and extract pointer handling into a separate helper function - Added
normalizeFullTypeNamehelper function to normalize individual type names while preserving pointer prefixes - Added comprehensive unit tests covering various generic type scenarios including pointers, multiple type parameters, and versioned imports
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| interfaces/generate.go | Refactored type normalization logic by extracting pointer handling into normalizeFullTypeName and updating normalizedGenericTypeName to support multiple type parameters |
| interfaces/generate_test.go | Added comprehensive unit tests for normalizedGenericTypeName covering single/multiple type parameters, pointer types, and versioned imports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| typeName = typeName[1:] | ||
| } | ||
|
|
||
| versionPattern := regexp.MustCompile(`/v\d+\.`) |
There was a problem hiding this comment.
The regex pattern is compiled on every function call. Since this function may be called multiple times during code generation (once per type parameter), consider moving the regex compilation to a package-level variable to improve performance. For example, declare var versionPattern = regexp.MustCompile(\/v\d+\.`)` at the package level and reuse it in this function.
| // Generic output types have the full import path in the string value, so we need to normalize it | ||
| pattern := regexp.MustCompile(`\[(.*?)\]`) | ||
| groups := pattern.FindStringSubmatch((str)) | ||
| pattern := regexp.MustCompile(`\[(.*)\]`) |
There was a problem hiding this comment.
The regex pattern is compiled on every function call. Since this function is called for each return type in method signatures, consider moving the regex compilation to a package-level variable to improve performance. For example, declare var genericTypePattern = regexp.MustCompile(\\[(.*)\]`)` at the package level and reuse it in this function.
| if versionPattern.MatchString(typeName) { | ||
| // Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse | ||
| importName = parts[len(parts)-2] + "." + strings.Split(parts[len(parts)-1], ".")[1] |
There was a problem hiding this comment.
Potential index out of bounds error. The code assumes that when versionPattern matches, parts[len(parts)-1] (the last path segment) will contain a dot and can be safely split to access index [1]. While this is true for well-formed versioned import paths like armappconfiguration/v2.ConfigurationStoresClientListResponse, malformed input could cause a panic. Consider adding a bounds check or using a more defensive approach, such as checking the length of the split result before accessing index [1].
| if versionPattern.MatchString(typeName) { | |
| // Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse | |
| importName = parts[len(parts)-2] + "." + strings.Split(parts[len(parts)-1], ".")[1] | |
| if versionPattern.MatchString(typeName) && len(parts) >= 2 { | |
| // Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse | |
| lastParts := strings.Split(parts[len(parts)-1], ".") | |
| if len(lastParts) >= 2 { | |
| importName = parts[len(parts)-2] + "." + lastParts[1] | |
| } |
🤖 I have created a release *beep* *boop* --- ## [0.3.37](v0.3.36...v0.3.37) (2026-02-17) ### Features * Preserve pointer types in generic iterators ([#409](#409)) ([d4fe386](d4fe386)) ### Bug Fixes * **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.94.2 ([#407](#407)) ([41c4bc3](41c4bc3)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Release-As: v0.4.0